package com.rambo.sdh.common.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Create by rambo on 2016/10/20
 * 抽象控制类 放置公共属性和方法
 **/
public abstract class BaseController {
    //日志对象
    protected final static Logger log = LoggerFactory.getLogger(BaseController.class);

    /**
     * form表单提交 Date类型数据绑定
     */
    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }
}